package com.lgc.netdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.blankj.utilcode.util.LogUtils
import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val map:Map<String,String>?= mapOf("token" to "RMx8xcUdCiROOOUC","lang" to "zh_CN","query" to "北京")

        val httpApi:HttpApi=OkHttpApi()
        httpApi.get(map,"v2/place",object:IHttpCallback{//get请求
            override fun onSuccess(data: Any?) {
                LogUtils.i("data success:${(data as Response).body?.string()}")
            }

            override fun onFailed(error: Any?) {
                LogUtils.e("data failed:${error.toString()}")
            }

        })
        //取消请求调用
        map?.let { httpApi.cancelRequest(it) }


        httpApi.post(LoginReq(),"",object:IHttpCallback{//post请求
            override fun onSuccess(data: Any?) {
                LogUtils.i("result success:${data.toString()}")
            }

            override fun onFailed(error: Any?) {
                LogUtils.i("result failed:${error.toString()}")
            }

        })
    }




    data class LoginReq(val mobi:String="18648957777",val password:String="cn5123456")
}